﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;

namespace DelonixRegiaHotel
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Staff st = new Staff();
            st.StaffID = tbxUsername.Text;
            st.Password = tbxPwd.Text;
            Staff st1 = new Staff();
            st1 = LoginDBManager.CheckLogin(st);

            if (tbxUsername.Text.Equals("") || tbxPwd.Text.Equals(""))
            {
                MessageBox.Show("Please ensure you fill in both textbox");
            }

            else if (st1.AccessLevel >= 1 && st1.AccessLevel <= 3)
            {
                StaticSession.AccessLevel = st1.AccessLevel;
                StaticSession.StaffID = st1.StaffID;
                Form temp = new MainForm();
                hide_form();
                temp.Show();
            }

            else if(st1.AccessLevel == 4)
            {
                StaticSession.AccessLevel = st1.AccessLevel;
                StaticSession.StaffID = st1.StaffID;
                Form temp = new StaffEditInfo();
                hide_form();
                temp.Show();
            }
            else
            {
                MessageBox.Show("please check your username and password");
            }
        }

        public void hide_form()
        {
            this.Visible = false;
        }

    }
}
